package com.sims.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class BaseDao {
	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory(){
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory){
		this.sessionFactory=sessionFactory;
	}
	public Session getSession(){
		
		//getCurrentSession创建的session会和绑定到当前线程,而openSession不会。   
	    //getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSession必须手动关闭  
		//https://www.iteye.com/topic/733971
		Session session=sessionFactory.getCurrentSession();
		return session;
	}
}
